package com.thinkingstar.iads.projectcenter.serviceImpl;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.thinkingstar.iads.common.utils.InitSystemProperties;
import com.thinkingstar.iads.datacenter.entity.*;
import com.thinkingstar.iads.datacenter.entity.dao.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.bstek.urule.runtime.response.RuleExecutionResponse;
import com.thinkingstar.iads.common.jsonUtils.AjaxResult;
import com.thinkingstar.iads.common.utils.CommonDateUtil;
import com.thinkingstar.iads.common.utils.StringUtil;
import com.thinkingstar.iads.cs.sys.entity.SysUser;
import com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao;
import com.thinkingstar.iads.projectcenter.entity.PcProjectEquipmentEquip;
import com.thinkingstar.iads.projectcenter.entity.PcProjectEquipmentEquipInfo;
import com.thinkingstar.iads.projectcenter.entity.PcProjectInfo;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcEquipmentEquip;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcEquipmentSelfCheckResult;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectData;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectEquipmentEquipInfo;
import com.thinkingstar.iads.projectcenter.jsoup.api.JsoupElementServiceImpl;

/**
 * @ClassName: ProjectDesignManagerServiceImpl 
 * @Description: 项目相关信息维护
 * @author 1157372219@qq.com
 * @date  
 */
@IocBean
public class ProjectDesignManagerServiceImpl {

	@Inject
	Dao dao;

	@Inject
	private JsoupElementServiceImpl jsoupElementServiceImpl;
	
	@Inject 
	private DaoPcProjectData daoPcProjectData;
	
	@Inject
	private DaoDcProjectDesignContent daoDcProjectDesignContent;
	
	@Inject
	private DaoDcProjectDesignContentMajor daoDcProjectDesignContentMajor;
	
	@Inject CommonDao commonDao;
	
	@Inject
	private DaoDcFormField daoDcFormField;
	
	@Inject
	private DaoDcProjectFieldWidget daoDcProjectFieldWidget;

	@Inject
	private DaoDcProjectDesignCell daoDcProjectDesignCell;

	@Inject
	private DaoDcProjectMention daoDcProjectMention;
	
	@Inject
	private DaoPcEquipmentEquip daoPcEquipmentEquip;
	
	@Inject
	private DaoDcEquipmentEquip daoDcEquipmentEquip;
	
	@Inject
	private DaoDcEquipmentEquipInfo daoDcEquipmentEquipInfo;
	
	@Inject
	private DaoPcProjectEquipmentEquipInfo daoPcProjectEquipmentEquipInfo;
	
	@Inject
	private ProjectInitServiceImpl projectInitServiceImpl;
	
	@Inject
	private DaoDcProjectEquipmentField daoDcProjectEquipmentField;
	
	@Inject
	private DaoDcEquipment daoDcEquipment;
	
	@Inject
	private DaoPcEquipmentSelfCheckResult daoPcEquipmentSelfCheckResult;
	
	@Inject
	private DaoDcManufacturerEquipment daoDcManufacturerEquipment;
	
	
	public QueryResult findProjectList(NutMap nutMap){
		return daoPcProjectData.findAllProjectInfoList(nutMap);
	}
	
	public DaoPcEquipmentSelfCheckResult getDaoPcEquipmentSelfCheckResult(){
		return daoPcEquipmentSelfCheckResult;
	}
	
	public DaoDcEquipment getDaoDcEquipment(){
		return daoDcEquipment;
	}
	
	public AjaxResult delObject(Class<?> class1 , String obj_id){
		try {
			return commonDao.delObj(class1,obj_id)==1?AjaxResult.success("删除成功!"):AjaxResult.error("删除失败!");
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
				| SecurityException e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常,请重试!");
		}
	}


	public AjaxResult delProject(String project_id){
		try {
			return commonDao.delObj(PcProjectInfo.class,project_id)==1?AjaxResult.success("删除成功!"):AjaxResult.error("删除失败!");
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
				| SecurityException e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常,请重试!");
		}
	}
	
	public List<Map> findDesignContentByProjectId(NutMap nutMap){
		return daoDcProjectDesignContent.findDesignContentByProjectId(nutMap);
	}

	public AjaxResult updateProject(PcProjectInfo dcProjectInfo , HttpSession httpSession){
		if(dcProjectInfo == null){
			return AjaxResult.error("更新失败!");
		}
		SysUser user = (SysUser) httpSession.getAttribute("userSession");
		String project_id = dcProjectInfo.getId();
		if(StringUtils.isBlank(project_id)){
			dcProjectInfo.setCreate_time(CommonDateUtil.getDateTime());
			dcProjectInfo.setProject_user_name(user.getLoginname());
			PcProjectInfo object = daoPcProjectData.insert(dcProjectInfo);
			if(object != null){
				//列车对数表计算规则完成后初始化设备配备信息
				//projectInitServiceImpl.initEquipmentRelated(object.getId());
				return AjaxResult.success("项目更新成功!");
			}
		}else{
			PcProjectInfo update_obj = daoPcProjectData.fetch(project_id);
			update_obj.setProject_user_name(user.getLoginname());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setProject_code(dcProjectInfo.getProject_code());
			update_obj.setProject_name(dcProjectInfo.getProject_name());
			/*update_obj.setProject_short_name(dcProjectInfo.getProject_short_name());*/
			return daoPcProjectData.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
		return AjaxResult.error("更新失败!");
	}
	
	//查询项目匹配的专业序列
	public List<NutMap> getCorrelationMajorByPid(String pid){ 
		PcProjectInfo project_info = daoPcProjectData.fetch(pid);
		String [] content_ids = project_info.getProject_design_content_id().split(",");
		List <NutMap> data_list = daoDcProjectDesignContentMajor.findCorrelationMajorByContentId(StringUtil.getStrsplit(content_ids));
		return data_list;
	}
	
	/**
	 * 根据专业id以及项目id匹配资料
	 * @param major_id 专业id
	 * @param pid 项目id
	 * @return
	 */
	public List <DcProjectMentionInformation> getMentionDataListByMidAndPid(String major_id , String pid){
		PcProjectInfo project_info = daoPcProjectData.fetch(pid);
		String phase_id = project_info.getProject_design_phase_id();
		String [] content_ids = project_info.getProject_design_content_id().split(",");
		return daoDcProjectMention.getMentionDataByContentAndMajor(StringUtil.getStrsplit(content_ids), major_id, phase_id);
	}
	
	//更新提入资料表单项
	public AjaxResult updateMentionDataByTable(String mention_data_id , NutMap nutMap){
		DcProjectMentionInformation dcProjectMentionInformation = daoDcProjectMention.fetch(mention_data_id);
		String table_name = new StringBuffer("dc_mention_").append(dcProjectMentionInformation.getMention_information_code()).toString();
		String data_id = nutMap.getString("id");
		Boolean mention_type = dcProjectMentionInformation.getMention_information_type(); //资料类型
		int i = 0;
		if(StringUtils.isNotBlank(data_id)){
			i = commonDao.updateBeanById(table_name, nutMap);
		}else{
			commonDao.addBeanByMap(table_name, nutMap);
			i = 1;
		}
		return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}
	
	//更新提入资料表单项
	public AjaxResult updateEquipmentBudgetDataByTableName(String table_name , NutMap nutMap){
		String data_id = nutMap.getString("id");
		int i = 0;
		if(StringUtils.isNotBlank(data_id)){
			i = commonDao.updateBeanById(table_name, nutMap);
		}else{
			commonDao.addBeanByMap(table_name, nutMap);
			i = 1;
		}
		return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}
	
	//删除资料表单项
	public AjaxResult delMentionDataById(String mention_data_id , String id){
		DcProjectMentionInformation dcProjectMentionInformation = daoDcProjectMention.fetch(mention_data_id);
		String table_name = new StringBuffer("dc_mention_").append(dcProjectMentionInformation.getMention_information_code()).toString();
		Boolean mention_type = dcProjectMentionInformation.getMention_information_type(); //资料类型
		int i = 0;
		if(mention_type){
			i = commonDao.delBeanById(table_name, id);
		}
		return i==1?AjaxResult.success("更新成功"):AjaxResult.error("更新失败!");
	}
	
	//删除设备概算
	public AjaxResult delEquipmentBudgetDataById(String table_name , String id){
	    int i = commonDao.delBeanById(table_name, id);
		return i==1?AjaxResult.success("更新成功"):AjaxResult.error("更新失败!");
	}
	
	//结构化提入资料维护
	public Object mentionDataManage(NutMap param , HttpServletRequest request) throws IOException{
		String mention_data_id = param.getString("mention_data_id");
		String project_id = param.getString("project_id");
		DcProjectMentionInformation dcProjectMentionInformation = daoDcProjectMention.fetch(mention_data_id);
		Boolean mention_type = dcProjectMentionInformation.getMention_information_type(); //资料类型
		String table_name = new StringBuffer("dc_mention_").append(dcProjectMentionInformation.getMention_information_code()).toString();
		param.put("table_name", table_name);
		if(daoDcProjectFieldWidget.findFormTypeByTableName(table_name)){
			QueryResult data_list = commonDao.findDataByTableName(param);
			//非结构化数据
			List <DcProjectFieldWidget> field_list = daoDcProjectFieldWidget.findWidgetByTableName(table_name);
			//非结构化数据表单格式
			NutMap data_map = new NutMap();
			List<?> list = data_list.getList();
			if(!list.isEmpty()){
				data_map = (NutMap) list.get(0);
			}
			String result_html = jsoupElementServiceImpl.getDiyHtmlForForm(field_list,data_map,project_id,request);
			NutMap result_map = new NutMap();
			result_map.put("form", result_html);
			return result_map;
		}
		if(mention_type){//结构化数据维护
			//结构化数据表单表头
			//List <NutMap> field_list = daoDcFormField.queryColumnList(table_name);
			List <DcProjectFieldWidget> field_list = daoDcProjectFieldWidget.findWidgetByTableName(table_name);
			//判断结构化数据表单是否是纯数据表单(所有的控件类型都是text)
			QueryResult data_list = commonDao.findDesignCellDataByTableName(param);

			NutMap data_map = new NutMap();
			data_map.put("title_list", field_list);
			if (table_name.equals("dc_mention_jydcss")) {
				//既有动车设施，根据城市 去 动车设施数据库查询 名称和规模
				if(data_list.getList().size()==0) {
					PcProjectInfo project_info = daoPcProjectData.fetch(project_id);
					initJydcssTable(project_id,table_name,project_info.getProject_design_content_name());
				}
			}
			data_map.put("data_list", commonDao.findDesignCellDataByTableName(param));
			return data_map;
		}else{
			QueryResult data_list = commonDao.findDataByTableName(param);
			//非结构化数据
			List <DcProjectFieldWidget> field_list = daoDcProjectFieldWidget.findWidgetByTableName(table_name);
			//非结构化数据表单格式
			NutMap data_map = new NutMap();
			List<?> list = data_list.getList();
			if(!list.isEmpty()){
				data_map = (NutMap) list.get(0);
			}
			String result_html = jsoupElementServiceImpl.getDiyHtml(field_list,data_map,project_id,request);
			NutMap result_map = new NutMap();
			result_map.put("form", result_html);
			return result_map;
		}
		
	}

	public AjaxResult initJydcssTable(String project_id,String jydcss_table,String sjnr){
		//先清空数据
		String sql = "delete from "+jydcss_table+" where project_id='"+project_id+"'";
		Sql sqls = Sqls.create(sql);
		dao.execute(sqls);

		String gcqdcs = "";
		String gczdcs = "";
		String table_name = "";
		if (sjnr.equals("机务动车专业工作量计算")){
			//去提入资料 项目信息 里 取 工程起点和工程终点城市
			table_name = "项目信息";
		} else {
			//去提入资料 项目基本信息 里 取 工程起点和工程终点城市
			table_name = "%项目基本信息%";
		}
		List<DcProjectMentionInformation> dcProjectMentionInformations = daoDcProjectMention.query(Cnd.where("mention_information_name","like",table_name).and("del_flag","=","0"));
		String xx = "";
		if (null!=dcProjectMentionInformations && dcProjectMentionInformations.size()>0) {
			xx = "dc_mention_"+dcProjectMentionInformations.get(0).getMention_information_code();
		}
		NutMap param = new NutMap();
		param.put("project_id",project_id);
		param.put("table_name",xx);
		QueryResult data_list = commonDao.findDataByTableName(param);

		if (data_list.getList().size()>0) {
			List<?> re = data_list.getList();
			NutMap map = (NutMap) re.get(0);
			if (StringUtils.isNotEmpty(map.get("gcqd").toString())) {
				gcqdcs = map.get("gcqd").toString();
			}
			if (sjnr.equals("机务动车专业工作量计算")){
				if (StringUtils.isNotEmpty(map.get("gcqid").toString())) {
					gczdcs = map.get("gcqid").toString();
				}
			} else{
				if (StringUtils.isNotEmpty(map.get("gczd").toString())) {
					gczdcs = map.get("gczd").toString();
				}
			}

		}

		if (StringUtils.isNotEmpty(gcqdcs)) {
			List<NutMap> list = getJydcssByCity(gcqdcs);
			for (int i=0;i<list.size();i++) {
				list.get(i).put("cs",list.get(i).get("crh_info_city").toString());
				list.get(i).put("mc",list.get(i).get("crh_info_name").toString());
				list.get(i).put("gm",list.get(i).get("crh_info_size").toString());
				list.get(i).put("serial_number",i+1);
				list.get(i).put("project_id",project_id);
				list.get(i).remove("crh_info_city");
				list.get(i).remove("crh_info_name");
				list.get(i).remove("crh_info_size");
				list.get(i).put("id", UUID.randomUUID().toString().replace("-",""));
			}
			//开始插入新数据
			if (null != list &&list.size()>0) {
				list.get(0).put(".table",jydcss_table);
				dao.insert(list);
			}
		}
		if (StringUtils.isNotEmpty(gczdcs)) {
			List<NutMap> list = getJydcssByCity(gczdcs);
			for (int i=0;i<list.size();i++) {
				list.get(i).put("cs",list.get(i).get("crh_info_city").toString());
				list.get(i).put("mc",list.get(i).get("crh_info_name").toString());
				list.get(i).put("gm",list.get(i).get("crh_info_size").toString());
				list.get(i).put("serial_number",i+1);
				list.get(i).put("project_id",project_id);
				list.get(i).remove("crh_info_city");
				list.get(i).remove("crh_info_name");
				list.get(i).remove("crh_info_size");
				list.get(i).put("id", UUID.randomUUID().toString().replace("-",""));
			}
			//开始插入新数据
			if (null != list &&list.size()>0) {
				list.get(0).put(".table",jydcss_table);
				dao.insert(list);
			}
		}
		return AjaxResult.success();
	}

	public AjaxResult initJyjwssTable(String project_id,String jyjwss_table,String sjnr){
		//先清空数据
		String sql = "delete from "+jyjwss_table+" where project_id='"+project_id+"'";
		Sql sqls = Sqls.create(sql);
		dao.execute(sqls);

		String gcqdcs = "";
		String gczdcs = "";
		String table_name = "";
		if (sjnr.equals("机务动车专业工作量计算")){
			//去提入资料 项目信息 里 取 工程起点和工程终点城市
			table_name = "项目信息";
		} else {
			//去提入资料 项目基本信息 里 取 工程起点和工程终点城市
			table_name = "%项目基本信息%";
		}
		List<DcProjectMentionInformation> dcProjectMentionInformations = daoDcProjectMention.query(Cnd.where("mention_information_name","like",table_name).and("del_flag","=","0"));
		String xx = "";
		if (null!=dcProjectMentionInformations && dcProjectMentionInformations.size()>0) {
			xx = "dc_mention_"+dcProjectMentionInformations.get(0).getMention_information_code();
		}
		NutMap param = new NutMap();
		param.put("project_id",project_id);
		param.put("table_name",xx);
		QueryResult data_list = commonDao.findDataByTableName(param);

		if (data_list.getList().size()>0) {
			List<?> re = data_list.getList();
			NutMap map = (NutMap) re.get(0);
			if (StringUtils.isNotEmpty(map.get("gcqd").toString())) {
				gcqdcs = map.get("gcqd").toString();
			}
			if (sjnr.equals("机务动车专业工作量计算")){
				if (StringUtils.isNotEmpty(map.get("gcqid").toString())) {
					gczdcs = map.get("gcqid").toString();
				}
			} else{
				if (StringUtils.isNotEmpty(map.get("gczd").toString())) {
					gczdcs = map.get("gczd").toString();
				}
			}

		}

		if (StringUtils.isNotEmpty(gcqdcs)) {
			List<NutMap> list = getJyjwssByCity(gcqdcs);
			for (int i=0;i<list.size();i++) {
				list.get(i).put("cs",list.get(i).get("city").toString());
				list.get(i).put("mc",list.get(i).get("facilities_name").toString());
				list.get(i).put("gm",list.get(i).get("scale").toString());
				list.get(i).put("serial_number",i+1);
				list.get(i).put("project_id",project_id);
				list.get(i).remove("city");
				list.get(i).remove("facilities_name");
				list.get(i).remove("scale");
				list.get(i).put("id", UUID.randomUUID().toString().replace("-",""));
			}
			//开始插入新数据
			if (null != list &&list.size()>0) {
				list.get(0).put(".table",jyjwss_table);
				dao.insert(list);
			}
		}
		if (StringUtils.isNotEmpty(gczdcs)) {
			List<NutMap> list = getJyjwssByCity(gczdcs);
			for (int i=0;i<list.size();i++) {
				list.get(i).put("cs",list.get(i).get("city").toString());
				list.get(i).put("mc",list.get(i).get("facilities_name").toString());
				list.get(i).put("gm",list.get(i).get("scale").toString());
				list.get(i).put("serial_number",i+1);
				list.get(i).put("project_id",project_id);
				list.get(i).remove("city");
				list.get(i).remove("facilities_name");
				list.get(i).remove("scale");
				list.get(i).put("id", UUID.randomUUID().toString().replace("-",""));
			}
			//开始插入新数据
			if (null != list &&list.size()>0) {
				list.get(0).put(".table",jyjwss_table);
				dao.insert(list);
			}
		}
		return AjaxResult.success();
	}

	//结构化提入资料维护  只看 设计评审
	public Object mentionDataManageForSjps(NutMap param , HttpServletRequest request) throws IOException{
		String mention_data_id = param.getString("mention_data_id");
		String project_id = param.getString("project_id");
		DcProjectMentionInformation dcProjectMentionInformation = daoDcProjectMention.fetch(mention_data_id);
		Boolean mention_type = dcProjectMentionInformation.getMention_information_type(); //资料类型
		String table_name = new StringBuffer("dc_mention_").append(dcProjectMentionInformation.getMention_information_code()).toString();
		param.put("table_name", table_name);
		QueryResult data_list = commonDao.findDataByTableName(param);
		if(mention_type){//结构化数据维护
			//结构化数据表单表头
			List <NutMap> field_list = daoDcFormField.queryColumnList(table_name);
			NutMap data_map = new NutMap();
			data_map.put("title_list", field_list);
			data_map.put("data_list", data_list);
			return data_map;
		}else{
			//非结构化数据
			List <DcProjectFieldWidget> field_list = daoDcProjectFieldWidget.findWidgetByTableName(table_name);
			//非结构化数据表单格式
			NutMap data_map = new NutMap();
			List<?> list = data_list.getList();
			if(!list.isEmpty()){
				data_map = (NutMap) list.get(0);
			}
			String result_html = jsoupElementServiceImpl.getDiyHtmlForSjps(field_list,data_map,project_id,request);
			NutMap result_map = new NutMap();
			result_map.put("form", result_html);
			return result_map;
		}

	}

	public Object findListByEquipmentEquipId(NutMap param){
		return daoPcProjectEquipmentEquipInfo.findResultByEquipId(param);
	}
	
	public Object updateEquipmentEquip(PcProjectEquipmentEquip pcProjectEquipmentEquip){
		if(pcProjectEquipmentEquip == null){
			return AjaxResult.error("更新失败!");
		}
		String equip_id = pcProjectEquipmentEquip.getId();
		if(StringUtils.isBlank(equip_id)){
			pcProjectEquipmentEquip.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoPcEquipmentEquip.insert(pcProjectEquipmentEquip);
			return object != null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else {
			PcProjectEquipmentEquip update_obj = daoPcEquipmentEquip.fetch(equip_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_equip_name(pcProjectEquipmentEquip.getEquipment_equip_name());
			int i = daoPcEquipmentEquip.update(update_obj);
			return i == 1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
	
	public Object updateEquipmentEquipInfo(PcProjectEquipmentEquipInfo pcProjectEquipmentEquipInfo){
		if(pcProjectEquipmentEquipInfo == null){
			return AjaxResult.error("更新失败!");
		}
		String equip_info_id = pcProjectEquipmentEquipInfo.getId();
		if(StringUtils.isBlank(equip_info_id)){
			pcProjectEquipmentEquipInfo.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoPcProjectEquipmentEquipInfo.insert(pcProjectEquipmentEquipInfo);
			return object != null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			PcProjectEquipmentEquipInfo update_obj = daoPcProjectEquipmentEquipInfo.fetch(equip_info_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_num(pcProjectEquipmentEquipInfo.getEquipment_num());
			update_obj.setComment(pcProjectEquipmentEquipInfo.getComment());
			int i = daoPcProjectEquipmentEquipInfo.update(update_obj);
			return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
	
	//设备选型
	public Object equipmentSelection(PcProjectEquipmentEquipInfo pcProjectEquipmentEquipInfo){
		if(pcProjectEquipmentEquipInfo == null){
			return AjaxResult.error("选型失败,请重试!");
		}
		String equip_info_id = pcProjectEquipmentEquipInfo.getId();
		PcProjectEquipmentEquipInfo update_obj = daoPcProjectEquipmentEquipInfo.fetch(equip_info_id);
		update_obj.setEquipment_manufacturer_id(pcProjectEquipmentEquipInfo.getEquipment_manufacturer_id());
		update_obj.setEquipment_price(pcProjectEquipmentEquipInfo.getEquipment_price());
		return daoPcProjectEquipmentEquipInfo.update(update_obj)==1?AjaxResult.success("选型成功!"):AjaxResult.error("选型失败!");
	}
	
	//设备一键选型
	public AjaxResult allEquipmentEquip(String equip_id){
		if(StringUtils.isBlank(equip_id)){
			return AjaxResult.error("设备一键选型失败!");
		}
		List <PcProjectEquipmentEquipInfo> list = daoPcProjectEquipmentEquipInfo.findEquipmentEquipInfoByEquipId(equip_id);
		for(PcProjectEquipmentEquipInfo info : list){
			String equipment_id = info.getEquipment_id();
			List <DcManufacturerEquipment> manufacturer_list = daoDcManufacturerEquipment.findManufacturerByEquipmentId(equipment_id);
			for(DcManufacturerEquipment dcManufacturerEquipment : manufacturer_list){
				if("标准通用价格".equals(dcManufacturerEquipment.getEquipment_manufacturer_name())){
					info.setEquipment_manufacturer_id(dcManufacturerEquipment.getEquipment_manufacturer_id());
					info.setEquipment_price(dcManufacturerEquipment.getEquipment_price());
					daoPcProjectEquipmentEquipInfo.update(info);
				}
			}
		}
		return AjaxResult.success("设备一键选型成功!");
	}
	
	
	//查询设备配备信息
	public Object findEquipmentEquipListByProjectId(NutMap param){
		return daoPcEquipmentEquip.findEquipmentEquipList(param);
	}
	
	public DaoDcProjectEquipmentField getDaoDcProjectEquipmentField(){
		return daoDcProjectEquipmentField;
	}
	
	public DaoDcManufacturerEquipment getDaoDcManufacturerEquipment(){
		return daoDcManufacturerEquipment;
	}


	/** 根据项目内容和阶段获取 设计动车设施表*/
	public String getSjdcssTableName(String design_phase_id,String design_content_id) {
		String sqlStr = "select m.mention_information_code from dc_project_mention_information_content_major mc " +
				" left join dc_project_mention_information m on mc.project_mention_information_id=m.id " +
				" where mc.del_flag='0' and m.del_flag='0' and mc.project_design_phase_id='"+design_phase_id+"' and mc.content_id='"+design_content_id+"' and m.mention_information_name like '设计动车设施%'";
		List<Map> list = getDataListBySql(sqlStr);
		String result = "";
		for (int i=0;i<list.size();i++) {
			Map newMap = list.get(i);
			result = (String)newMap.get("mention_information_code");
		}
		return "dc_mention_"+result;
	}

	/**
	 * 根据 既有动车设施 里的 城市 查询 动车设施数据库里的 数据
	 *
	 * */
	public List<NutMap> getJydcssByCity(String cs) {
		String sqlStr = "select dci.crh_info_city,dci.crh_info_name,dci.crh_info_size from dc_crh_info dci " +
				" where dci.del_flag='0' and dci.crh_info_city ='"+cs+"' ";
		List<NutMap> list = getMapDataListBySql(sqlStr);
		return list;
	}

	/**
	 * 根据 既有机务设施 里的 城市 查询 机务设施数据库里的 数据
	 *
	 * */
	public List<NutMap> getJyjwssByCity(String cs) {
		String sqlStr = "select dci.city,dci.facilities_name,dci.scale from dc_carmaintenance_facility dci " +
				" where dci.city ='"+cs+"' ";
		List<NutMap> list = getMapDataListBySql(sqlStr);
		return list;
	}

	public List<Map> getDataListBySql(String sqlStr){
		Sql sql = Sqls.create(sqlStr);
		sql.setCallback(new SqlCallback() {
			@Override
			public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
				List<Map<String,Object>> list = new ArrayList<>();
				while (rs.next()){
					Map<String,Object> map = new HashMap<>();
					ResultSetMetaData metaData = rs.getMetaData();
					int count = metaData.getColumnCount();
					for (int i = count; i > 0; i--) {
						String filed = metaData.getColumnName(i);
						map.put(filed, rs.getString(filed));
					}
					list.add(map);
				}
				return list;
			}
		});
		dao.execute(sql);
		List<Map> list = sql.getList(Map.class);
		return list;
	}

	public List<NutMap> getMapDataListBySql(String sqlStr){
		Sql sql = Sqls.create(sqlStr);
		sql.setCallback(new SqlCallback() {
			@Override
			public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
				List<NutMap> list = new ArrayList<>();
				while (rs.next()){
					NutMap map = new NutMap();
					ResultSetMetaData metaData = rs.getMetaData();
					int count = metaData.getColumnCount();
					for (int i = count; i > 0; i--) {
						String filed = metaData.getColumnName(i);
						map.put(filed, rs.getString(filed));
					}
					list.add(map);
				}
				return list;
			}
		});
		dao.execute(sql);
		List<NutMap> list = sql.getList(NutMap.class);
		return list;
	}
}

